package com.huoyun.car.service;

import java.util.List;

import com.huoyun.base.bean.Page;
import com.huoyun.car.bean.CarPubInfo;
import com.huoyun.car.bean.CarPubInfoCar;
import com.huoyun.car.bean.CarRoute;
import com.huoyun.car.dao.CarPubInfoDao;
import com.huoyun.car.dao.CarRouteDao;
import com.huoyun.car.model.CarPubInfoModel;
import com.huoyun.car.model.BidCarInfoModel;
import com.huoyun.car.service.evt.GetCarPubsByCityEvt;
import com.huoyun.car.service.evt.QueryCarForGoodsEvt;

public class CarPubInfoServiceImpl implements CarPubInfoService {

	private CarPubInfoDao carPubInfoDao;
	private CarRouteDao carRouteDao;

	public CarRouteDao getCarRouteDao() {
		return carRouteDao;
	}

	public void setCarRouteDao(CarRouteDao carRouteDao) {
		this.carRouteDao = carRouteDao;
	}

	@Override
	public void publishCarInfo(final CarPubInfo record) {
		// TODO Auto-generated method stub
		carPubInfoDao.insert(record);
	}

	public CarPubInfoDao getCarPubInfoDao() {
		return carPubInfoDao;
	}

	public void setCarPubInfoDao(final CarPubInfoDao carPubInfoDao) {
		this.carPubInfoDao = carPubInfoDao;
	}

	@Override
	public List<CarPubInfo> getInfoListByUserId(final int userId) {
		return carPubInfoDao.getInfoListByUserId(userId);
	}

	@Override
	public CarPubInfo getCarPubInfoById(final Long id) {
		// TODO Auto-generated method stub
		return carPubInfoDao.getCarPubInfoById(id);

	}

	@Override
	public void updateAll(final CarPubInfo carPubInfo) {
		carPubInfoDao.updateAll(carPubInfo);
	}
	
	public List<String> getCarNumberListByUserId(int userId) {
		return carPubInfoDao.getCarNumberListByUserId(userId);
	}
	
	public void deleteCarPubInfoById(long carPubInfoId) {
		carPubInfoDao.deleteCarPubInfoById(carPubInfoId);
	}

	@Override
	public List<CarPubInfoCar> getInfoListByCondition(final CarPubInfo condition) {
		return carPubInfoDao.getInfoListByCondition(condition);
	}

	@Override
	public void saveCarRoute(CarRoute carRoute) {
		// TODO Auto-generated method stub
		carRouteDao.saveCarRoute(carRoute);
	}

	@Override
	public List<CarPubInfoModel> getCarPubInfoItemListByUserId(long userId) {
		return carPubInfoDao.getCarPubInfoItemListByUserId(userId);
	}

	@Override
	public void updateCarPubInfoStatus(long carPubInfoId, int status) {
		// TODO Auto-generated method stub
		this.carPubInfoDao.updateStatus(carPubInfoId, status);
	}

	@Override
	public List<CarPubInfoModel> getCarPubInfoModelListByUsername(String username) {
		// TODO Auto-generated method stub
		return this.carPubInfoDao.getCarPubInfoModelListByUsername(username);
	}

	@Override
	public List<CarPubInfoModel> getCarPubInfoModelListByCarNumber(
			String carNumber) {
		// TODO Auto-generated method stub
		return this.carPubInfoDao.getCarPubInfoModelListByCarNumber(carNumber);
	}

	@Override
	public List<CarPubInfoModel> getOfflineCarPubInfoModelList(long userId) {
		// TODO Auto-generated method stub
		return this.carPubInfoDao.getOfflineCarPubInfoModelList(userId);
	}
	
	/**
	 * 货主搜索车辆
	 * @param queryCarForGoodsEvt 请求参数
	 * @return
	 */
	@Override
	public Page queryCarForGoods(QueryCarForGoodsEvt queryCarForGoodsEvt)
	{
		com.huoyun.car.dao.evt.QueryCarForGoodsEvt evt = new com.huoyun.car.dao.evt.QueryCarForGoodsEvt();
		evt.setStartProvince(queryCarForGoodsEvt.getStartProvince());
		evt.setStartCity(queryCarForGoodsEvt.getStartCity());
		evt.setEndProvince(queryCarForGoodsEvt.getEndProvince());
		evt.setEndCity(queryCarForGoodsEvt.getEndCity());
		evt.setPageNo(queryCarForGoodsEvt.getPageNo());
		evt.setPageCount(queryCarForGoodsEvt.getPageCount());
		evt.setGoodsId(queryCarForGoodsEvt.getGoodsId());
		
		//获取匹配车辆的总记录数
		long totalRecord = carPubInfoDao.queryCarCountForGoods(evt);
		
		Page page = new Page();
		page.setPageNo(queryCarForGoodsEvt.getPageNo());
		page.setPageCount(queryCarForGoodsEvt.getPageCount());
		
		//设置总记录数
		page.setTotalRecord(totalRecord);
		
		//设置显示的记录列表
		page.setObjectList(carPubInfoDao.queryCarForGoods(evt));
		
		return page;
	}
	
	/**
	 * 查询货物的所有应标车源信息
	 * 
	 * @author 刘晓宁
	 * @param goodsId 货物id
	 * 
	 * @return 符合的车源信息列表
	 */
	public List<BidCarInfoModel> queryBidCars(long goodsId, String[] carIds)
	{
		return carPubInfoDao.queryBidCars(goodsId, carIds);
	}
	/**
	 * 为首页查询车源信息
	 * @author yang
	 */
	@Override
	public Page getCarPubsByCity(GetCarPubsByCityEvt evt) {
		// TODO Auto-generated method stub
		com.huoyun.car.dao.evt.GetCarPubsByCityEvt daoEvt=new com.huoyun.car.dao.evt.GetCarPubsByCityEvt();
		daoEvt.setProvince(evt.getProvince());
		daoEvt.setCity(evt.getCity());
		daoEvt.setPageCount(evt.getPageCount());
		daoEvt.setPageNo(evt.getPageNo());
		
		
		Page page = new Page();
		page.setPageCount(evt.getPageCount());
		page.setPageNo(evt.getPageNo());
		page.setTotalRecord(8);
		page.setObjectList(carPubInfoDao.getCarPubsByCity(daoEvt));
		
		return page;
	}

}
